<template>
  <a-modal
    style="width: 50%"
    :title="titleMap[mode]"
    :visible="visible"
    :confirm-loading="confirmLoading"
    :destroyOnClose="true"
    @cancel="handleCancel"
    width="750px"
    :maskClosable="false">
    <div style="margin-top: 12px;">
      <a-form-model ref="ruleAddForm" :model="addForm" :rules="addRules">
        <!-- <a-form-model-item label="人员" prop="personId" :labelCol="labelCol" :wrapperCol="wrapperCol">
                    <a-input v-model="addForm.personId" placeholder="请输入人员"></a-input>
                </a-form-model-item> -->

        <a-form-model-item label="人脸图片" prop="faceUrl" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-model="addForm.faceUrl" type="text" />
        </a-form-model-item>

      </a-form-model>
    </div>
    <template slot="footer">
      <a-button key="back" @click="handleCancel">
        关闭
      </a-button>
      <a-button type="primary" :visible="visibleBtn" :loading="loadingBtn" @click="handleOk">
        保存
      </a-button>
    </template>
  </a-modal>
</template>
<script>
import { addPersonFaces, detailPersonFaces } from '@/api/clockingIn'
export default {
    data () {
        return {
            addRules: {
                faceUrl: [
                    { required: true, message: '请选择人脸图片路径!', trigger: 'blur' }
                ]
            },
            addForm: {
                personId: '',
                organizationUnitCode: ''
            },
            labelCol: {
                xs: { span: 24 },
                sm: { span: 5 }
            },
            wrapperCol: {
                xs: { span: 24 },
                sm: { span: 16 }
            },
            disable: true,
            visible: false,
            confirmLoading: false,
            loading: false,
            visibleBtn: false,
            loadingBtn: false,
            mode: 'add',
            titleMap: {
                add: '新增',
                edit: '编辑'
            },
            rowData: null
        }
    },
    methods: {
        // 显示
        open (row) {
            // this.mode = mode;
            console.log(row)
            this.visible = true
            return this
        },
        // setData(row) {
        //     console.log(row)
        //     this.rowData = row
        //     this.addForm.personId
        //     if (this.mode == "edit") {
        //         detailPersonFaces(row.personId).then(res => {
        //             if (res.code == 200) {
        //               console.log(res)
        //             }
        //         })
        //     }
        // },

        // 关闭
        handleCancel () {
            this.visible = false
            this.loadingBtn = false
            this.visibleBtn = false
            this.$emit('success')
        },
        // 确认
        handleOk () {
            this.loadingBtn = true
            this.visibleBtn = true
            this.$refs.ruleAddForm.validate(valid => {
                if (valid) {
                    // let Api = this.mode == 'add' ? addPersonFaces : editOrg
                    addPersonFaces(this.addForm).then(res => {
                        console.log(res)
                        if (res.code === 200) {
                            this.$notification['success']({
                                message: '提示',
                                description: '保存成功！',
                                duration: 8
                            })
                            this.$emit('success')
                            this.visible = false
                        } else {
                            this.$notification['error']({
                                message: '提示',
                                description: res.message,
                                duration: 8
                            })
                        }
                        this.visibleBtn = false
                        this.loadingBtn = false
                    })
                } else {
                    this.loadingBtn = false
                    this.visibleBtn = false
                    return false
                }
            })
        }
    }
}
</script>
<style scoped lang="less" ></style>
